package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.DBDao;

public class City_xml extends HttpServlet {

	private DBDao dbDao = new DBDao();
	
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/xml;charset=utf-8");
		PrintWriter out = response.getWriter();
		String provid = request.getParameter("provid");
		String sql = "select cityID, city from hat_city where father = " + "'" + provid + "'";
		ResultSet rs = dbDao.excuteSelect(sql);
		out.print("<citys>");
		try {
			while(rs.next()) {
				out.print("<city>");
				out.print("<id>");
				out.print(rs.getString("cityID"));
				out.print("</id>");
				out.print("<name>");
				out.print(rs.getString("city"));
				out.print("</name>");
				out.print("</city>");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbDao.close(rs);
		}
		out.print("</citys>");
		out.flush();
		out.close();
	}

}
